/**
 *
 */
package com.powersi.biz.base.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.powersi.biz.base.dto.ChooseShipDTO;
import com.powersi.biz.entity.SHIP;
import com.powersi.hygeia.framework.BaseDAOImpl;
import com.powersi.hygeia.framework.util.DAOHelper;
import com.powersi.hygeia.framework.util.DBHelper;
import com.powersi.hygeia.framework.util.UtilFunc;

/**
 * The Class ShipDAOImpl.
 */
public class ShipDAOImpl extends BaseDAOImpl implements ShipDAO {

	private static final String TABLE_NAME = "bs_ship";





	/*
	 * (non-Javadoc)
	 *
	 * @see com.powersi.sys.message.dao.ShipDAO#queryList(java.lang.String,
	 * java.lang.String, java.util.Map)
	 */
	@Override
	public List queryList( Map map) {
		ArrayList params = new ArrayList();
		StringBuffer lSQL = new StringBuffer();

		lSQL.append(" select id, ");
		lSQL.append("         ship_name, ");
		lSQL.append("         ship_model, ");
		lSQL.append("         ship_no,  ");
		lSQL.append("         valid_flag  ");
		lSQL.append("         from bs_ship bs where 1=1  ");

		lSQL.append("    and valid_flag = '1' ");


		lSQL.append("  order by ship_name ");

		return DBHelper.executeList(lSQL.toString(), UtilFunc.toArray(params));
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * com.powersi.sys.message.dao.ShipDAO#insertBulletin(com.powersi.sys
	 * .message.entity.SysBulletins)
	 */
	@Override
	public int insertShip(SHIP ship) {
		return DAOHelper.insert(TABLE_NAME, ship);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * com.powersi.sys.message.dao.ShipDAO#updateBulletin(com.powersi.sys
	 * .message.entity.SysBulletins)
	 */
	@Override
	public int updateShip(SHIP ship) {
		return DAOHelper.update(TABLE_NAME, ship, null, new String[] {
				"id" });
	}


	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * com.powersi.sys.message.dao.ShipDAO#deleteBulletin(java.lang.Long)
	 */
	@Override
	public int deleteShip(Long id) {
		int ret = DBHelper
				.update("update bs_ship set valid_flag = '0' where id = ? and valid_flag = '1' ",
						new Object[] { id });
		return ret;
	}





	@Override
	public SHIP queryShipInfo(Long id) {


		Map param = new HashMap();
		param.put("id", id);
		param.put("valid_flag", 1);
		return DAOHelper.queryForObject("BS_SHIP", param , new String[] {
				"id", "valid_flag" },SHIP.class);
	}

	@Override
	public List getShipList(ChooseShipDTO chooseShipDTO) {

		StringBuffer strSQL = new StringBuffer();
		strSQL.append(" select * from bs_ship bs where 1=1 ");

		String strCond = chooseShipDTO.getQueryCond();
		if (!UtilFunc.isEmptyString(strCond)) {
			strSQL.append(" and (bs.ship_name like '%"+strCond+"%' or bs.ship_model like '%"+strCond+"%' or bs.ship_no like '%"+strCond+"%' ) ");
		}

		String strShipName = chooseShipDTO.getShip_name();
		if (!UtilFunc.isEmptyString(strShipName)) {
			strSQL.append(" and bs.ship_name like '%"+strShipName+"%' ");
		}

		return DBHelper.executeList(strSQL.toString());
	}
}
